<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        textarea {
            width: 300px;
            height: 200px;
        }
    </style>
</head>

<body>
    <!-- 8. 字数统计  https://www.jq22.com/yanshi3282  -->
    <div id="app">
        <textarea v-model="count" @input="add"></textarea>
        <span v-if="count.length <= total">剩余字数:{{residue}}/{{total}}</span>
    </div>
</body>
<script src="Vue.js"></script>
<script>


    let { createApp, ref } = Vue
    createApp({
        setup() {
            let count = ref('')
            let total = 20
            let residue = ref(total - count.value.length)
            function add() {
                count.value = count.value.slice(0, total)
                residue.value = total - count.value.length
            };
            return {
                count,
                residue,
                add,
                total
            };
        }
    }).mount("#app");
</script>

</html>